#============================================================================
# Copyright (C) 2016, han_gangbiao. All rights reserved.
# Use of this source code is governed by a GPL-v2 license that can be found in the License file.
#
#// CreateDate	: [2015-6-26 23:01:20]
#// Creator		: han_gangbiao [jackhen] [http://my.oschina.net/jackhen]
#
#// FileInfo	: Makefile for latency
#============================================================================

EXE_TARGET=latency$(FN_D)

SRCS += \
	$(wildcard *.cpp)

CFLAGS += -g -pipe -Wall
CFLAGS += \
	-I../../../ \

LFLAGS += \
	-L../../../ \
	-lsmartrpc$(FN_D) \
	-lpthread -ldl -lrt


D?=0

OBJS += $(patsubst %.cpp, %.o, $(filter %.cpp, $(SRCS)))
OBJS += $(patsubst %.cc, %.o, $(filter %.cc, $(SRCS)))
OBJS += $(patsubst %.c, %.o, $(filter %.c, $(SRCS)))
DEPS += $(patsubst %.o, %.d~, $(OBJS))

GCC=gcc
GXX=g++
AR=ar

ifeq ($(D), 0)
CFLAGS += -O2 -fno-strict-aliasing
else
FN_D=_d
endif

ifdef SO_TARGET
LFLAGS += -DPIC -fPIC
endif

.PHONY : all clean
all : $(A_TARGET) $(SO_TARGET) $(EXE_TARGET)
clean:
	rm -f $(A_TARGET) $(SO_TARGET) $(EXE_TARGET) $(OBJS) $(DEPS)

ifdef A_TARGET
$(A_TARGET) : $(OBJS)
	$(AR) crvs $(A_TARGET) $(OBJS)
endif

ifdef SO_TARGET
$(SO_TARGET) : $(OBJS)
	$(GXX) -shared -rdynamic $(CFLAGS) -o $(SO_TARGET) $(OBJS) $(LFLAGS)
endif

ifdef EXE_TARGET
$(EXE_TARGET) : $(OBJS)
	$(GXX) $(CFLAGS) -o $(EXE_TARGET) $(OBJS) $(LFLAGS)
endif

.SUFFIXES : .cpp .c .cc

.cpp.o :
	$(GXX) $(CFLAGS) -MMD -MF $*.d~ -c -o $@ $<

.c.o :
	$(GCC) $(CFLAGS) -MMD -MF $*.d~ -c -o $@ $<

.cc.o :
	$(GXX) $(CFLAGS) -MMD -MF $*.d~ -c -o $@ $<

-include $(DEPS)


